@@ -1,7 +1,4 @@ |
||
| 1 |
-To Do |
|
| 2 |
-====== |
|
| 3 | 1 |
|
| 4 |
-- Repeated requests to the same domain, ends up causing a block. This app should be storing queries for 12-24 hours. |
|
| 2 |
+====== |
|
| 5 | 3 |
|
| 6 |
-- add some error checking |
|
| 7 | 4 |
|
@@ -4,6 +4,9 @@ require 'haml' |
||
| 4 | 4 |
require 'json' |
| 5 | 5 |
require 'ostruct' |
| 6 | 6 |
|
| 7 |
+before do |
|
| 8 |
+ response['Access-Control-Allow-Origin'] = '*' |
|
| 9 |
+end |
|
| 7 | 10 |
|
| 8 | 11 |
helpers do |
| 9 | 12 |
|
@@ -13,6 +16,22 @@ helpers do |
||
| 13 | 16 |
end |
| 14 | 17 |
end |
| 15 | 18 |
|
| 19 |
+ def whois_lookup |
|
| 20 |
+ @lookup_info = Whois.query(params[:url]) |
|
| 21 |
+ @admin_contacts = Hash[@lookup_info.admin_contacts[0].each_pair.to_a] |
|
| 22 |
+ @technical_contacts = Hash[@lookup_info.technical_contacts[0].each_pair.to_a] |
|
| 23 |
+ |
|
| 24 |
+ return {
|
|
| 25 |
+ "domain" => @lookup_info.domain, |
|
| 26 |
+ "created_on" => @lookup_info.created_on, |
|
| 27 |
+ "expires_on" => @lookup_info.expires_on, |
|
| 28 |
+ "whois_server" => @lookup_info.referral_whois, |
|
| 29 |
+ "nameservers" => @lookup_info.nameservers, |
|
| 30 |
+ "admin_contacts" => @admin_contacts, |
|
| 31 |
+ "techical_contacts" => @technical_contacts |
|
| 32 |
+ } |
|
| 33 |
+ end |
|
| 34 |
+ |
|
| 16 | 35 |
end |
| 17 | 36 |
|
| 18 | 37 |
|
@@ -30,43 +49,18 @@ end |
||
| 30 | 49 |
get '/lookup' do |
| 31 | 50 |
begin |
| 32 | 51 |
cache_for_day |
| 33 |
- |
|
| 34 |
- @lookup_info = Whois.query(params[:url]) |
|
| 35 |
- admin_contacts = Hash[@lookup_info.admin_contacts[0].each_pair.to_a] |
|
| 36 |
- technical_contacts = Hash[@lookup_info.technical_contacts[0].each_pair.to_a] |
|
| 37 |
- |
|
| 38 |
- @formatted_response = {
|
|
| 39 |
- "domain" => @lookup_info.domain, |
|
| 40 |
- "created_on" => @lookup_info.created_on, |
|
| 41 |
- "expires_on" => @lookup_info.expires_on, |
|
| 42 |
- "whois_server" => @lookup_info.referral_whois, |
|
| 43 |
- "nameservers" => @lookup_info.nameservers, |
|
| 44 |
- "admin_contacts" => admin_contacts, |
|
| 45 |
- "techical_contacts" => technical_contacts |
|
| 46 |
- } |
|
| 52 |
+ @formatted_response = whois_lookup |
|
| 47 | 53 |
haml :lookup |
| 48 | 54 |
rescue |
| 49 | 55 |
haml :error |
| 50 | 56 |
end |
| 51 | 57 |
end |
| 52 | 58 |
|
| 59 |
+ |
|
| 53 | 60 |
get '/lookup.json' do |
| 54 | 61 |
begin |
| 55 | 62 |
cache_for_day |
| 56 |
- |
|
| 57 |
- @lookup_info = Whois.query(params[:url]) |
|
| 58 |
- admin_contacts = Hash[@lookup_info.admin_contacts[0].each_pair.to_a] |
|
| 59 |
- technical_contacts = Hash[@lookup_info.technical_contacts[0].each_pair.to_a] |
|
| 60 |
- |
|
| 61 |
- content_type :json |
|
| 62 |
- { :domain => @lookup_info.domain,
|
|
| 63 |
- :created_on => @lookup_info.created_on, |
|
| 64 |
- :expires_on => @lookup_info.expires_on, |
|
| 65 |
- :whois_server => @lookup_info.referral_whois, |
|
| 66 |
- :nameservers => @lookup_info.nameservers, |
|
| 67 |
- :admin_contacts => admin_contacts, |
|
| 68 |
- :techical_contacts => technical_contacts |
|
| 69 |
- }.to_json |
|
| 63 |
+ whois_lookup.to_json |
|
| 70 | 64 |
rescue |
| 71 | 65 |
{"Error" => "Bad Request"}.to_json
|
| 72 | 66 |
end |